<template>
  <van-nav-bar
    title="订单评论"
    left-text="返回"
    left-arrow
    @click-left="onClickLeft"
  />
  <VanForm @submit="onProfile">
    <van-field
      name="comment"
      label="评论内容"
      label-align="right"
      label-width="4.5em"
      colon
    >
      <template #input>
        <textarea v-model="comment"> </textarea>
        <div class="num">/180字</div>
      </template>
    </van-field>

    <!-- 头像 -->
    <van-field
      name="avatar"
      label="图片上传"
      label-align="right"
      label-width="4.5em"
      colon
    >
      <template #input>
        <van-uploader v-model="fileList" :max-count="5" />
      </template>
    </van-field>

    <!-- 邀请码 -->

    <div style="margin: 16px">
      <van-button round block type="primary" native-type="submit">
        提交评论
      </van-button>
    </div>
  </VanForm>
</template>

<script>
import { showLoadingToast, showToast } from "vant";
export default {
  data() {
    return {
      comment: "",
      fileList: [],
      LoginUser: this.$cookies.get("LoginAuth"),
      form: [],
    };
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    onProfile(value) {
      let _this=this;
      // 封装更新数据
      let data = {
        busid: this.LoginUser.id,
        comment: this.comment,
        orderid: this.$route.query.orderid,
      };
      // 头像
      let avatarFile = value.avatar[0].file ? value.avatar[0].file : {};

      if (avatarFile || JSON.stringify(avatarFile) != "{}") {
        data.avatar = avatarFile;
      }
        showLoadingToast({
        message: "提交评论中...",
        forbidClick: true,
        onClose: async function () {
           let result = await _this.$api.toComment(data);
               if (result.code === 1) {
        showToast({
          type: "success",
          message: result.msg,
          onClose: () => {
            _this.$router.push("/user/order/index");
          },
        });

        return false;
      } else {
        showNotify({
          type: "warning",
          message: result.msg,
        });

        return false;
      }
        }})
      // 发起请求
     

    },
   
        
  },
};
</script>

<style>
textarea {
  position: relative;
  width: 98%;
  height: 200px;
}
.num {
  right: 10px;
  top: 220px;
  position: absolute;
}
.updata {
  margin-left: 10px;
}
.send {
  margin-top: 20px;
}
</style>